﻿using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Autofac;
using Dexter.Dependency.Autofac.Extensions;
using Dexter.Dependency.Installation;

namespace Dexter.Dependency.Autofac {
	public class AutofacInstaller : IDexterInstaller {
		#region IDexterInstaller Members

		public IEnumerable <ILayerInstaller> GetInstallers ( IEnumerable <Assembly> assemblies ) {
			ContainerBuilder builder = new ContainerBuilder ( );
			builder.RegisterAssemblyTypes ( assemblies.ToArray ( ) )
					.As <ILayerInstaller> ( )
					.SingleInstance ( );
			

			var container = builder.Build ( );
			return container.ResolveAll <ILayerInstaller> ( );
		}

		#endregion
	}
}